package org.jxc.service;


import java.util.List;

import org.hibernate.SessionFactory;
import org.jxc.dao.OutOrderProductDAO;
import org.jxc.domain.OutOrderProduct;
import org.springframework.beans.factory.annotation.Autowired;
import org.team4.dao.DAOFactory;
import org.team4.exception.CRUDException;
import org.team4.service.IService;
import org.team4.vo.Page;

public class OutOrderProductService implements IService {

	private OutOrderProductDAO outOrderProductDAO ;
	
	@Autowired
	public void setSessionFactory(SessionFactory sessionFactory) {
		outOrderProductDAO = (OutOrderProductDAO) DAOFactory.getDAO(sessionFactory, OutOrderProductDAO.class);
	}

	public Page<OutOrderProduct> listPagination(Page<OutOrderProduct> page) throws CRUDException {
		return outOrderProductDAO.pagination(page, "from OutOrderProduct","");
	}

	public void save(OutOrderProduct ooProduct) throws CRUDException {
		outOrderProductDAO.save(ooProduct);
	}

	public List findByOutOrderId(String id) throws CRUDException {
		return outOrderProductDAO.find("from OutOrderProduct where outOrder.id = '" + id + "'", null);
	}
	
	public void delByOutOrderId(String id) throws CRUDException{
		List<OutOrderProduct> list = this.findByOutOrderId(id);
		if(list != null && !list.isEmpty()){
			for (int i = 0; i < list.size(); i++) {
				OutOrderProduct temp = list.get(i);
				outOrderProductDAO.delete(temp);
			}
		}
	}

}
